// pages/answer/answer.js
Page({
  data: {
    nowQue: 13,
    allQue: 42,
    progress: 0,
    questionTitle: '在大多数情况下，你会：',
    popShow: false,
    pulseShow: false,
    eggShow: true,
    money: '2.00',
    answerShow: true,
    openEggId: 0,
    redbagShow: false,
    questionList: [{
      id: 1,
      isRight: true,
      title: '谨言慎行多于信口随心谨言慎行多于信口随心'
    }, {
      id: 2,
      isRight: false,
      title: '信口随心多于谨言慎行'
    }],
    questionPoint: [{
      id: 0,
      canOpen: false,
      isOpened: false,
      dragenImg: '../../images/dragen_img1.png'
    }, {
      id: 1,
      canOpen: false,
      isOpened: false,
      dragenImg: '../../images/dragen_img2.png'
    }, {
      id: 2,
      canOpen: false,
      isOpened: false,
      dragenImg: '../../images/dragen_img3.png'
    }],
    redBagDragen: [{
      id: 0,
      body: '../../images/dragen_img1_body.png',
      head: '../../images/dragen_img1_head.gif',
      animate: '',
      show: false
    }, {
      id: 1,
      body: '../../images/dragen_img2_body.png',
      head: '../../images/dragen_img2_head.png',
      animate: 'swing',
      show: false
    }, {
      id: 2,
      body: '../../images/dragen_img3_body.png',
      head: '../../images/dragen_img3_head.png',
      animate: 'pulse',
      show: false
    }]
  },
  quesionProgress: function(){
    var now = this.data.nowQue, all = this.data.allQue, progress = this.data.progress;
    var point = this.data.questionPoint;
    if (now == 42) {
      point[0].canOpen = true;
      point[1].canOpen = true;
      point[2].canOpen = true;
    } else if (now >= 28) {
      point[0].canOpen = true;
      point[1].canOpen = true;
    } else if (now >= 14) {
      point[0].canOpen = true;
    }
    progress = Math.floor((now / all) * 100);
    this.setData({
      progress,
      questionPoint: point
    })
  },
  onReady: function () {
    this.quesionProgress();
  },
  answerTapFun: function (e){
    console.log(e.currentTarget.dataset.right);
    var nowQue = this.data.nowQue;
    nowQue ++;
    this.setData({
      nowQue
    });
    this.quesionProgress();
    // if (e.currentTarget.dataset.right){
    //   wx.showToast({
    //     title: '回答正确!!',
    //     icon: 'success'
    //   })
    // }else{
    //   wx.showToast({
    //     title: '回答错误。。。',
    //     icon: 'none'
    //   })
    // }
  },
  pointTapFun: function (e){
    var that = this;
    var openEggId = e.currentTarget.id, redBagDragen = this.data.redBagDragen;
    if(e.currentTarget.dataset.canopen){
      console.log('砸龙蛋！');
      for (let i = 0; i < redBagDragen.length; i++) {
        if (redBagDragen[i].id == openEggId) {
          redBagDragen[i].show = true;
        } else {
          redBagDragen[i].show = false;
        }
      }
      that.setData({
        redBagDragen
      });
      setTimeout(function(){
        that.setData({
          pulseShow:true,
        });
      },2000);
    }else{
      return;
    }
    this.setData({
      eggShow: true,
      popShow: true,
      openEggId
    })
  },
  hitEggFun: function(e) {
    var that = this;
    setTimeout(function(){
      that.setData({
        redbagShow: true
      })
    },1000);
    this.setData({
      pulseShow: false,
      eggShow: false
    })
  },
  closePop: function(e) {
    var that = this;
    var openEggId = this.data.openEggId, answerShow = this.data.answerShow;
    if(openEggId == 2){
      answerShow = false;
    }
    this.setData({
      popShow: false,
      redbagShow: false,
      answerShow
    })
  },
  startChoose: function(e) {
    wx.navigateTo({
      url: '../trade/trade',
    })
  }
})